/**
 * Course Project for User Interface Programming I, 2011
 * Group 19
 */
package justdoit.view.model;

import javax.swing.AbstractListModel;
import javax.swing.ComboBoxModel;
import justdoit.model.Theme;

/**
 * The model for presenting the Theme comboBox
 * @author Can
 */
public class ThemeComboBoxModel
        extends AbstractListModel
        implements ComboBoxModel {

    private Theme[] themes;
    private int currentThemeIndex;

    public ThemeComboBoxModel() {
        themes = new Theme[]{
                    new Theme(Theme.SYSTEM),
                    new Theme(Theme.METAL),
                    new Theme(Theme.MOTIF)
                };
        currentThemeIndex = 1;
    }

    public String getSelectedTheme() {
        return themes[currentThemeIndex].getTheme();
    }

    public int getSize() {
        return themes.length;
    }

    public Object getElementAt(int index) {
        return themes[index].getDisplayTheme();
    }

    public void setSelectedItem(Object anItem) {
        for (int i = 0; i < themes.length; i++) {
            if (themes[i].getDisplayTheme().equals(anItem)) {
                currentThemeIndex = i;
                return;
            }
        }
        System.out.println("ERROR :: ThemeComboBoxModel :: setSelectedItem");
    }

    public Object getSelectedItem() {
        return themes[currentThemeIndex].getDisplayTheme();
    }
}
